<?php
/*
订单分类
*/
class Con_customer extends Acan{
	public $defaultAct='list';
	function __construct($ainfo=null){
		parent::__construct($ainfo=null);
		if(empty($this->id) || $this->id == '*'){$this->id = '0';}
		$this->model = Afun_db()->model(Adb_asale_customer);
	}
	//--列表
	function Act_list(){
		$obj = Afun_acan_new('list');
		$key_name = $this->model->key_name;
		$columnrr = $this->model->comment;//初始栏目
		$column = $obj->column($this->model,$columnrr,$_POST['acolumn']);
		$column_html = $obj->column_html($this->model,$column);
		$column_json = $obj->form_json($this->model);
		if(empty($this->title)){$this->title = '订单列表';}
		$form_val_status = array('1'=>'开始交易','2'=>'交易中','3'=>'成功','4'=>'失败');
		//分页函数
	//	$con->where = "`pid`='$this->id'";
		$page->theurl = $this->Aactr.'-'.$this->id;
		$page->by = $this->model->key_name;
		$page->page = '20';
		$page->counts = $this->model->count($con);	//统计总数目
		$pages = Afun_apage($page);
		$con->order = "a.$pages->orderby";
		$con->limit = $pages->limit;
		//分页结束
		$list = $this->model->findAll($con);
		include $this->Atpl();
	}
	//批量更新
	function Act_save(){
		Afun_post_auth();
		if($this->id == 'one'){
			$save = $_POST['save'];
			$key = $_POST['save'][$this->model->key_name];
			unset($_POST['save'][$this->model->key_name]);
			if(!empty($key)){
				$msg = $this->model->updatePk($save,$key);
			}else{
				$msg = $this->model->save($save);
			}
		}elseif(is_array($_POST['save'])){
			foreach($_POST['save'] as $i=>$vals){
				$this->model->updatePk($vals,$vals['key']);
			}
		}
		echo $msg;
	}
	//添加
	function Act_add(){
		Afun_post_auth();
		$_POST['add']['pid'] = $this->id;
		$_POST['add']['class'] = $_POST['add']['class']+1;
		if($this->model->save($_POST['add'])){
			Afun_refresh('添加成功','referrer');
		}else{Afun_refresh('添加失败','referrer');}
			
	}
	//删除
	function Act_del(){
		Afun_post_auth();
		if($this->model->deletePk($this->id)){
			echo '删除成功';
		}
	}
	//删除所选
	function Act_delall(){
		Afun_post_auth();
		foreach($_POST['chk'] as $key=>$val){
			if(empty($vala))
				$vala = "'$val'";
			else
				$vala .=",'$val'";
		}
		$this->model->delete($this->model->key_name." IN ($vala)");
		Afun_refresh("删除成功",'referrer');
	}
	
}

?>